//
//  IMMoreFunctionView.m
//  WeiYiMei
//
//  Created by 李叶夫 on 2019/7/6.
//  Copyright © 2019年 liyefu. All rights reserved.
//

#import "IMMoreFunctionView.h"
#import "IMMoreFunctionCell.h"

@interface IMMoreFunctionView ()<UICollectionViewDataSource,UICollectionViewDelegate>

@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UICollectionViewFlowLayout *layout;

@property (nonatomic, strong) NSArray *dataSource;

@end

@implementation IMMoreFunctionView

- (void)setupSubViews
{
    self.backgroundColor = kColorF2F2F2;
    
    self.layout = [[UICollectionViewFlowLayout alloc] init];
    CGFloat margin = 20;
    CGFloat w = (kScreenW - margin*5) / 4;
    CGFloat h = 80;
    self.layout.itemSize = CGSizeMake(w, h);
    self.layout.sectionInset = UIEdgeInsetsMake(10, margin, 10, margin);
    self.layout.minimumLineSpacing = margin;
    self.layout.minimumInteritemSpacing = 10;
    self.layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.collectionView = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:self.layout];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    self.collectionView.pagingEnabled = YES;
    self.collectionView.backgroundColor = self.backgroundColor;
    [self.collectionView registerClass:[IMMoreFunctionCell class] forCellWithReuseIdentifier:NSStringFromClass([IMMoreFunctionCell class])];
    [self addSubview:self.collectionView];
}

- (void)layoutSubviews
{
    self.collectionView.frame = self.bounds;
}

#pragma mark - UICollectionViewDataSource,UICollectionViewDelegate

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return self.dataSource.count;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    NSArray *sec = self.dataSource[section];
    return sec.count;
}

// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    IMMoreFunctionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([IMMoreFunctionCell class]) forIndexPath:indexPath];
    NSArray *sec = self.dataSource[indexPath.section];
    cell.source = sec[indexPath.row];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.didSelectedPhotoHandle) {
        self.didSelectedPhotoHandle();
    }
}






- (NSArray *)dataSource
{
    if (!_dataSource) {
        _dataSource = @[@[@{@"img":@"input_add_pic",@"title":@"相册"}]];
    }
    return _dataSource;
}


@end
